package com.dyb.demo.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexTest {

    public static void main(String[] args) {
        String s = "Twas brillig, and the slithy toves\n" +
                "Did gyre and gimble in the wabe;\n" +
                "All mimsy were the borogoves,\n" +
                "And the mome raths outgrabe.\n" +
                "\"Beware the Jabberwock, my son!\n" +
                "The jaws that bite, the claws that catch!\n" +
                "Beware the Jubjub bird, and shun\n" +
                "The frumious Bandersnatch.";
        String regex = "(?m)(\\S+)\\s+((\\S+)\\s+(\\S+))$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(s);
        while(matcher.find()) {
            for (int i = 0; i <= matcher.groupCount(); i++) {
                System.out.print("["+ matcher.group(i) +"]");
            }
            System.out.println();
        }
    }
}
